//
//  MainTabBarController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/5/30.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "MainTabBarController.h"

#import "HomeViewController.h"
#import "BusinessTableViewController.h"
#import "ActViewController.h"
#import "ShopCarViewController.h"
#import "MineTableViewController.h"
#import "BaseNavigationController.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTarBarViews];
}

- (void)setupTarBarViews
{
    //首页
    HomeViewController *homeCtrl = [[HomeViewController alloc] init];
    [self addChildViewCtrlWithTitle:@"首页" image:@"tabar_notselected1" selctedImage:@"tabar_selected1" ctrl:homeCtrl];
    
    //商家
    BusinessTableViewController *businessCtrl = [[BusinessTableViewController alloc] init];
    [self addChildViewCtrlWithTitle:@"商家" image:@"tabar_notselected2" selctedImage:@"tabar_selected2" ctrl:businessCtrl];
    
    //活动
    ActViewController *actCtrl = [[ActViewController alloc] init];
    [self addChildViewCtrlWithTitle:@"活动" image:@"tabar_notselected3" selctedImage:@"tabar_selected3" ctrl:actCtrl];
    
    
    //购物车
    ShopCarViewController *shopCarCtrl = [[ShopCarViewController alloc] init];
    [self addChildViewCtrlWithTitle:@"购物车" image:@"tabar_notselected4" selctedImage:@"tabar_selected4" ctrl:shopCarCtrl];
    
    //我的
    MineTableViewController *mineCtrl = [[MineTableViewController alloc] init];
    [self addChildViewCtrlWithTitle:@"我的" image:@"tabar_notselected5" selctedImage:@"tabar_selected5" ctrl:mineCtrl];

}

- (void)addChildViewCtrlWithTitle:(NSString *)title image:(NSString *)image selctedImage:(NSString *)selectImage ctrl:(UIViewController *)ctrl{

    ctrl.tabBarItem.image = [UIImage imageNamed:image];
    //如果图片上面包括了icon与文字，要把图片往下移动的话。可以使用下面这句代码
    //    ctrl.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    //解决图片变蓝的问题
    UIImage *originalImage = [UIImage imageNamed:selectImage];
    ctrl.tabBarItem.selectedImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    设置标题
//        ctrl.tabBarItem.title = title;
//        ctrl.navigationItem.title = title;

    ctrl.title = title;
    
    //初始化文字的属性
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    dic[NSForegroundColorAttributeName] = DEFAULT_COLOR;
    
    //设置tabbarItem 标题的文字属性
    [ctrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];

    BaseNavigationController *navCtrl = [[BaseNavigationController alloc] initWithRootViewController:ctrl];
    [self addChildViewController:navCtrl];
    
}


@end
